﻿using Sustainalytics.ClientDW.Synchronization.SyncESGData.AbstractClassesAndInterfaces;
using Sustainalytics.SharedEntities.EsgResearch;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Sustainalytics.ClientDW.Synchronization.SyncESGData.SubPeerGroupKeyIssueLogic
{
    public class SubPeerGroupKeyIssueOrchestrator : IComprehensiveEsgSyncOrchestrator<KeyIssue>
    {
        private readonly IComprehensiveEsgSubPeerGroupKeyIssueQuery subPeerGroupKeyIssueQuery;
        private readonly SubPeerGroupKeyIssueMapper subPeerGroupKeyIssueMapper;
        private readonly SubPeerGroupKeyIssueCommand subPeerGroupKeyIssueCommand;
        public SubPeerGroupKeyIssueOrchestrator(SubPeerGroupKeyIssueQuery subPeerGroupKeyIssueQuery,
                                                SubPeerGroupKeyIssueMapper subPeerGroupKeyIssueMapper,
                                                SubPeerGroupKeyIssueCommand subPeerGroupKeyIssueCommand)
        {
            this.subPeerGroupKeyIssueQuery = subPeerGroupKeyIssueQuery;
            this.subPeerGroupKeyIssueMapper = subPeerGroupKeyIssueMapper;
            this.subPeerGroupKeyIssueCommand = subPeerGroupKeyIssueCommand;
        }

        async Task IComprehensiveEsgSyncOrchestrator<KeyIssue>.OrchestrateAsync(IList<KeyIssue> comprehensiveEsgEntities, IList<Guid> invalidatedCompaniesIds)
        {
            await subPeerGroupKeyIssueCommand.ExecuteAsync(subPeerGroupKeyIssueMapper.MapManyToMany(comprehensiveEsgEntities ?? subPeerGroupKeyIssueQuery.Get()));
        }
    }
}
